// 无 thisArg 传参版本

Array.prototype.lForEach = function (callback, thisArg) {
  if (typeof callback !== 'function') {
    throw new TypeError(`${callback} must be a function`);
  }

  const array = this;
  for (let i = 0; i < array.length; i++) {
    if (array.hasOwnProperty(i)) {
      callback.call(thisArg, array[i], i, array);
    }
  }
};

console.log([1, 2, 3, 4, 5].lForEach((item, index) => console.log(index + ':' + item)));

const calculator = {
  base: 10,
  print: function (numbers) {
    // 需求：遍历数组，每个元素加上 this.base（即 10）
    numbers.lForEach(function (num) {
      console.log(num + this.base);
    }, this);
  },
};

calculator.print([1, 2, 3, 4, 5]);
